package com.wys.singleton_demo.sari;

import com.wys.singleton_demo.hungry.HungrySingleton;
import com.wys.singleton_demo.lazy.InnerClassSingleton;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @author godShan
 * @Description:
 * @date 2019/5/5 11:51
 */
public class SariTest {

    public static void main(String[] args) {
        HungrySingleton innerClassSingleton = null;

        HungrySingleton innerClassSingleton1 = HungrySingleton.getInstance();
        try {
            FileOutputStream out = new FileOutputStream("aaa.obj");
            ObjectOutputStream outputStream = new ObjectOutputStream(out);
            outputStream.writeObject(innerClassSingleton1);
            outputStream.close();

            FileInputStream fis = new FileInputStream("aaa.obj");
            ObjectInputStream input = new ObjectInputStream(fis);
            innerClassSingleton = (HungrySingleton) input.readObject();
            input.close();

            System.out.println(innerClassSingleton == innerClassSingleton1);

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}
